package com.nanyang.tms.controller.export;

import com.nanyang.common.core.annotation.BindParam;
import com.nanyang.common.core.dict.CommonEnum;
import com.nanyang.common.core.domain.ApiResult;
import com.nanyang.common.core.exception.ServiceException;
import com.nanyang.tms.api.dto.request.export.ExportDataRequest;
import com.nanyang.tms.api.service.export.TmsExportDataRpcService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * <p>ExportDataController</p>
 * <p>Description:导出任务控制器</p>
 *
 * @author:
 * date: 2021/1/11 15:20
 * @Copyright: 2021 www.rongetong.cn Inc. All rights reserved.
 */
@RestController
@RequestMapping("/export/tms")
public class ExportDataController {

    @Reference(version = "1.0.0", timeout = 300000, check = false)
    private TmsExportDataRpcService tmsExportDataRpcService;

    /**
     * 导出
     */
    @BindParam
    @RequestMapping(value = "/waybill", method = RequestMethod.POST)
    public ApiResult<Boolean> exportData(@BindParam @Valid @RequestBody ExportDataRequest exportDataRequest) {
        ApiResult<Boolean> apiResult = tmsExportDataRpcService.exportDataMq(exportDataRequest);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }
}
